In [1]:
# common
import sys
import os
import os.path as op

# basic
import numpy as np
import pandas as pd
import xarray as xr
from scipy.io import loadmat
from time import time
import warnings
warnings.simplefilter('ignore')

# custom
from lib import calval

# functions
from lib import functions
In [2]:
# initial time to see the duration of the notebook
t0 = time()
In [3]:
# data 
p_data = op.join(os.getcwd(), 'data')

buoy       =  pd.read_pickle(op.join(p_data, 'Bilbao-Vizcaya Ext.pkl'))
csiro      =  pd.read_pickle(op.join(p_data, 'csiro_dataframe.pkl'))
satellite  =  xr.open_dataset(op.join(p_data, 'satellite_dataset.nc'))
bat_spain  =  np.loadtxt(op.join(p_data, 'SPAIN_2020_bath.dat'))
bat_gebco  =  xr.open_dataset(op.join(p_data, 'GEBCO_2019_bath.nc'))

print('---------------------------------------------------')
print('Time wasted reading the data: ' + str(round(time()-t0, 2)) + ' s')
print('---------------------------------------------------')
---------------------------------------------------
Time wasted reading the data: 11.77 s
---------------------------------------------------
In [4]:
t1 = time()
In [5]:
# creation of the main object

#######################################################
###   VALUES WILL HAVE TO BE INSERTED SO BE READY   ###
###   Satellite box :    South = 43.8               ###
###                      North = 44.2               ###
###                      West  = 356.2              ###
###                      East  = 356.6              ###
###   Time calibration:  False                      ###
###   Threshold :        0.015                      ###
#######################################################

# the Threshold allows us to delete not relevant information

calval_case = calval.CalVal(buoy, csiro, satellite, 'CSIRO', bat_spain, bat_gebco)

print('---------------------------------------------------')
print('Time wasted initializing the constructor: ' + str(round((time()-t1)/60, 2)) + ' m')
print('---------------------------------------------------')
Initializing data to calibrate... 
 
Satellite box values: 
South latitude: 43.8
North latitude: 44.2
West latitude: 356.2
East latitude: 356.6
 
 
Selecting the satellite data choosed... 
 
Satellite length: 8925 
 
Hindcast information able to calibrate: 301679 
 
Choose the way to calibrate the data: 
True: hindcast for each satellite 
False: satellite for each hindcast 
----- Select ----- : False
 
 
Performing the time calibration... 
 
Length of data to calibrate: 4210 
 
 
 
--------------------------------------------------------
SATELLITE CALIBRATION
-------------------------------------------------------- 
 
Constructing matrices and calibrating... 
 
Value to set the umbral for not enough data to calibrate, 
this value can be set to 0.01, 0.02 or 0.03: 
----- Threshold ----- : 0.015
 
 
 
 
Params used for the SATELLITE calibration are: 
 
[1.21858244 1.13665817 0.90206734 1.03003698 1.0842643  1.
 0.93985562 1.         1.51432808 1.         1.         1.
 0.99378739 1.02096614 1.02396711 1.15266712 1.         0.99623242
 1.         1.         1.         1.         1.         1.
 1.         1.         1.         1.         1.13767647 1.0674326
 1.10224544 1.        ]
 
 
Plotting just the data used to calibrate... 
 
Saving corrected results... 
 
 
  
 
 
 
--------------------------------------------------------
BUOY CALIBRATION
-------------------------------------------------------- 
 
Constructing matrices and calibrating... 
 
Value to set the umbral for not enough data to calibrate, 
this value can be set to 0.01, 0.02 or 0.03: 
----- Threshold ----- : 0.015
 
 
 
 
Params used for the BUOY calibration are: 
 
[1.02137022 0.96863021 0.86212164 0.8258302  1.         1.
 0.6200418  1.         1.         1.         1.         1.
 0.89601481 1.00653646 1.05089847 1.05307368 1.05729298 1.09789492
 1.         1.         1.         1.         1.         1.
 1.         1.         1.         1.         0.95365576 1.02998954
 1.1126027  1.17649791]
 
 
Plotting just the data used to calibrate... 
 
Saving corrected results... 
 
 
  
 
---------------------------------------------------
Time wasted initializing the constructor: 20.79 m
---------------------------------------------------
In [6]:
t1 = time()
In [8]:
calval_case.hindcast_sat_corr.to_pickle(op.join(p_data, 'csiro_dataframe_sat_corr.pkl'))
calval_case.hindcast_buoy_corr.to_pickle(op.join(p_data, 'csiro_dataframe_buoy_corr.pkl'))
In [10]:
# comparisons

#######################################################
###   VALUES WILL HAVE TO BE INSERTED SO BE READY   ###
###   Number of years :    2                        ###
###   Years :              2006 2007                ###
#######################################################

calval_case.buoy_comparison('raw')
--------------------------------------------------------
RAW comparison will be performed
-------------------------------------------------------- 
 
Number of years: 2
Years separated by one space: 2006 2007
 
 
Comparing data... 
 
In [11]:
calval_case.buoy_comparison('sat_corr')
--------------------------------------------------------
SAT_CORR comparison will be performed
-------------------------------------------------------- 
 
Number of years: 2
Years separated by one space: 2006 2007
 
 
Comparing data... 
 
In [12]:
calval_case.buoy_comparison('buoy_corr')
--------------------------------------------------------
BUOY_CORR comparison will be performed
-------------------------------------------------------- 
 
Number of years: 2
Years separated by one space: 2006 2007
 
 
Comparing data... 
 
In [13]:
print('---------------------------------------------------')
print('Time wasted comparing: ' + str(round((time()-t1)/60, 2)) + ' m')
print('---------------------------------------------------')
---------------------------------------------------
Time wasted comparing: 2.77 m
---------------------------------------------------
In [14]:
t1 = time()
In [15]:
# validations

calval_case.buoy_validation('raw')
--------------------------------------------------------
RAW validation will be performed
-------------------------------------------------------- 
 
Validating and plotting validated data... 
 
Length of data to validate: 59119 
 
In [16]:
calval_case.buoy_validation('sat_corr')
--------------------------------------------------------
SAT_CORR validation will be performed
-------------------------------------------------------- 
 
Validating and plotting validated data... 
 
Length of data to validate: 59119 
 
In [17]:
calval_case.buoy_validation('buoy_corr')
--------------------------------------------------------
BUOY_CORR validation will be performed
-------------------------------------------------------- 
 
Validating and plotting validated data... 
 
Length of data to validate: 59119 
 
In [18]:
print('---------------------------------------------------')
print('Time wasted comparing: ' + str(round((time()-t1)/60, 2)) + ' m')
print('---------------------------------------------------')
---------------------------------------------------
Time wasted comparing: 17.85 m
---------------------------------------------------
In [19]:
t1 = time()
In [20]:
# map

#######################################################
###   VALUES WILL HAVE TO BE INSERTED SO BE READY   ###
###   Map box :          South = 43.0               ###
###                      North = 44.4               ###
###                      West  = -4.6               ###
###                      East  = -2.4               ###
###   Map parameters :   grid_step = 0.2            ###
###                      depth = 300                ###
###   Hindcast box :     Longitude = -3.6           ###
###                      Latitude = 44.0            ###
#######################################################

calval_case.region_map()
 

MAP BOUNDARYS: 
--------------------------------------------------------
South latitude: 43.0
North latitude: 44.4
West latitude: -4.6
East latitude: -2.4
Grid step resolution for the meridians: 0.2
Maximum value for the bathymetry (+): 300
-------------------------------------------------------- 
 
Plotting gebco bathymetry... 
 
Plotting granulated bathymetry for near coast... 
 
La batimetría llega hasta: -299.0
Coordinates for the hindcast: 
Longitude for the hindcast point: -3.6
Latitude for the hindcast point: 44.0
In [21]:
print('---------------------------------------------------')
print('Time wasted plotting the map: ' + str(round((time()-t1)/60, 2)) + ' m')
print('---------------------------------------------------')
---------------------------------------------------
Time wasted plotting the map: 1.78 m
---------------------------------------------------
In [22]:
print('---------------------------------------------------')
print('TOTAL time of the script: ' + str(round((time()-t0)/60, 2)) + ' m')
print('---------------------------------------------------')
---------------------------------------------------
TOTAL time of the script: 43.61 m
---------------------------------------------------